package com.xique.door.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.xique.door.bean.domain.UserCompany;
import com.xique.door.service.IUserCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 用户企业中间表Controller
 *
 * @author ww
 * @date 2021-12-21
 */
@RestController
@RequestMapping("/userCompany")
public class UserCompanyController extends BaseController
{
    @Autowired
    private IUserCompanyService userCompanyService;

    /**
     * 查询用户企业中间表列表
     */
    @PreAuthorize(hasPermi = "oms:userCompany:list")
    @GetMapping("/list")
    public TableDataInfo list(UserCompany userCompany)
    {
        startPage();
        List<UserCompany> list = userCompanyService.selectUserCompanyList(userCompany);
        return getDataTable(list);
    }

    /**
     * 导出用户企业中间表列表
     */
    @PreAuthorize(hasPermi = "oms:userCompany:export")
    @Log(title = "用户企业中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCompany userCompany) throws IOException
    {
        List<UserCompany> list = userCompanyService.selectUserCompanyList(userCompany);
        ExcelUtil<UserCompany> util = new ExcelUtil<UserCompany>(UserCompany.class);
        util.exportExcel(response, list, "用户企业中间表数据");
    }

    /**
     * 获取用户企业中间表详细信息
     */
    @PreAuthorize(hasPermi = "oms:userCompany:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(userCompanyService.selectUserCompanyById(userId));
    }

    /**
     * 新增用户企业中间表
     */
    @PreAuthorize(hasPermi = "oms:userCompany:add")
    @Log(title = "用户企业中间表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCompany userCompany)
    {
        return toAjax(userCompanyService.insertUserCompany(userCompany));
    }

    /**
     * 修改用户企业中间表
     */
    @PreAuthorize(hasPermi = "oms:userCompany:edit")
    @Log(title = "用户企业中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCompany userCompany)
    {
        return toAjax(userCompanyService.updateUserCompany(userCompany));
    }

    /**
     * 删除用户企业中间表
     */
    @PreAuthorize(hasPermi = "oms:userCompany:remove")
    @Log(title = "用户企业中间表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userCompanyService.deleteUserCompanyByIds(userIds));
    }
}
